<template>
	<view class="my_container">
		<CustomNavbarTwo :title="pageTitle" />
		<view class="my_container_body">
			<view class="my_container_body_head"></view>
			<view class="my_container_body_body">
				<view class="query-box">
					<view class="input_find">
						<u-search @clickIcon="search" @blur="blur" @search="search" height="80rpx" Number="28rpx"
							:showAction="false" shape="round" bgColor="background: #FFFFFF;" v-model="keyword"
							placeholder="搜索城市/区县/地点"></u-search>
					</view>
					<view class="address">
						<image class="one" src="../../static/imags/dingwei.png"></image>
						<view class="two">当前选中：{{ keyword ? keyword : '全部' }}</view>
						<!-- 					<image class="three" src="../../static/imags/zfx.png" @click="getMyLoction"></image>
					<view class="four" @click="getMyLoction">重新定位</view> -->
					</view>
					<view class="input_find">
						<u-search @click="handleDialog" :disabled="userInfo.flagSearch == 0" @clickIcon="search"
							@blur="blur" @search="search" height="80rpx" Number="28rpx" :showAction="false"
							shape="round" bgColor="background: #FFFFFF;" v-model="remark"
							placeholder="搜你想找的品种"></u-search>
					</view>
				</view>
				<view class="item-box">
					<view class="item" v-for="(item, index) in itemList" :key="index" @click="goDetail(item.userId)">
						<view class="head">
							<image class="item-img" :src="item.avatar" mode="aspectFill"></image>
							<view class="item-info">
								<view class="item-title">
									<text class="title-text">{{ item.nickName }}</text>
									<text class="member-tag">{{ item.vipTypeName }}</text>
								</view>
								<view class="item-details">
									<text class="item-meta">联系方式: ******</text>
									<text class="item-right">主营: {{ item.industry }}</text>
								</view>
								<view class="abc">
									<image class="view_imag" src="../../static/imags/ditu.png"></image>
									<text class="abc_o">地址: {{ showLocation(item.province, item.city) }}</text>
									<text class="abc_t">{{ item.createTime }}</text>
								</view>
							</view>
						</view>
						<view class="footer">
							<view class="num-list">
								<view class="text">发布</view>
								<view class="show">{{ item.pubInfoCount }}</view>
							</view>
							<view class="num-list">
								<view class="text">浏览</view>
								<view class="show">{{ item.watchCount }}</view>
							</view>
							<view class="num-list">
								<view class="text">粉丝</view>
								<view class="show">{{ item.fansCount }}</view>
							</view>
							<view class="num-list">
								<view class="text">点赞</view>
								<view class="show">{{ item.likeCount }}</view>
							</view>
						</view>
					</view>
				</view>
				<view v-show="show" style="height: 70rpx; line-height: 70rpx; width: 100%">
					<u-loadmore icon :status="status" />
				</view>
			</view>
		</view>
		<u-modal :show="showDialog" @confirm="handleConfirm">
			<view class="slot-content">
				<image src="/static/images/hz.jpg" mode=""></image>
			</view>
		</u-modal>
	</view>
</template>
<script>
	import CustomNavbarTwo from '@/components/CustomNavbarTwo.vue';
	import locationFormatter from '@/util/locationFormatter';
	import { mapState } from 'vuex'; // 关键导入
	const api = require('../../util/api.js');
	export default {
		components: {
			CustomNavbarTwo
		},
		data() {
			return {
				showDialog: false,
				content: '合作厂家专区',
				pageTitle: '附近会员',
				showSex: false,
				keyword: '',
				remark: '',
				province: '',
				city: '',
				lat: '',
				lon: '',
				itemList: [],
				status: 'loading',
				show: true,
				pageSize: 6,
				pageNum: 1,
				total: 0
			};
		},
		onLoad() {
			this.getMyLoction();
		},
		computed: {
			...mapState(['userInfo', 'pubInfoUserInfo'])
		},
		onPullDownRefresh() {
			// 下拉刷新的处理逻辑
			this.pageNum = 1;
			this.status = 'loading';
			this.itemList = [];
			this.getData();
		},
		onReachBottom() {
			if (this.total == this.itemList.length) {
				this.status = 'nomore';
				this.show = true;
				return;
			}
			this.show = true;
			this.pageNum++;
			this.getData();
		},
		methods: {
			handleDialog() {
				// uni.showToast({
				// 	title: '合作厂家专区',
				// 	icon: 'error',
				// 	duration: 2000
				// });
				this.showDialog = true;
				// console.log(6666);
			},
			handleConfirm() {
				this.showDialog = false;
			},
			showLocation(pro, city) {
				let displayName;
				if (pro && city) {
					displayName = locationFormatter.format(pro, city);
				} else {
					displayName = '未知';
				}
				return displayName;
			},
			goDetail(userId) {
				uni.navigateTo({
					url: '/page/market/index?id=' + userId
				});
			},
			getMyLoction() {
				console.log(this.userInfo, 44);
				this.keyword = this.userInfo.city ? this.userInfo.city : '';
				this.getData();
				return;
				uni.showLoading({
					title: '定位中,请稍后'
				});
				const _that = this;
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						_that.lat = res.latitude;
						_that.lon = res.longitude;
						_that.getAddressByLanLen(res.latitude, res.longitude);
					},
					complete: function(res) {
						uni.hideLoading();
					}
				});
			},
			getAddressByLanLen(lat, lon) {
				let data = {
					lat: lat,
					lon: lon
				};
				this.$https.post(this.$api.getAddressByLanLen, data).then((res) => {
					uni.hideLoading();
					if (res.code === 200) {
						const data = res.data;
						this.city = data.cityName;
						if (data.provinceName != data.cityName) {
							this.province = data.provinceName;
						}
						this.getData();
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				});
			},
			search() {
				console.log('search');
				this.pageNum = 1;
				this.getData();
			},
			blur() {
				console.log('blur');
			},
			getData() {
				const query = {
					pageSize: this.pageSize,
					pageNum: this.pageNum,
					keyword: this.keyword,
					remark: this.remark
				};
				this.$https.post(this.$api.getPubUserNearBy, query).then((res) => {
					if (res.code === 200) {
						if (this.pageNum == 1) {
							this.itemList = [];
						}
						const data = res.data;
						this.total = res.total;
						this.itemList = [...this.itemList, ...res.rows];
						if (this.total == 0) {
							this.status = 'nomore';
							this.show = true;
						} else {
							this.show = false;
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
						this.show = false;
					}
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	.my_container {
		width: 100%;

		::v-deep .u-modal__content {
			// padding: 50rpx 100rpx;
		}

		.slot-content {
			image {
				width: 500rpx;
				height: 400rpx;
			}
		}

		.my_container_body {
			width: 750rpx;
			height: 100%;
			min-height: 1644rpx;
			background: linear-gradient(180deg, #ddffde 0%, #f6f6f6 29%, #f6f6f6 100%);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			font-style: normal;
			text-transform: none;

			.my_container_body_head {
				width: 686rpx;
				height: 176rpx;
			}

			.my_container_body_body {
				width: 686rpx;
				margin-left: 32rpx;
				position: relative;

				.query-box {
					z-index: 999;
					padding: 20rpx 30rpx;
					width: 100%;
					position: fixed;
					top: 176rpx;
					right: 0;
					background: #ddffde;
				}

				.input_find {
					background: #ffffff;
					border-radius: 100rpx 100rpx 100rpx 100rpx;
					height: 80rpx;
					width: 100%;
				}

				.address {
					margin-top: 26rpx;
					margin-bottom: 26rpx;
					display: flex;
					height: 38rpx;
					width: 686rpx;

					.one {
						width: 36rpx;
						height: 38rpx;
					}

					.two {
						margin-left: 6rpx;
						height: 38rpx;
						width: 496rpx;
						line-height: 38rpx;
						font-size: 32rpx;
						font-family: Inter, Inter;
						font-weight: 500;
						color: #000000;
						text-align: left;
						font-style: normal;
						text-transform: none;
					}

					.three {
						height: 32rpx;
						width: 32rpx;
						margin-left: 10rpx;
						margin-top: 3rpx;
					}

					.four {
						margin-left: 2rpx;
						width: 104rpx;
						height: 38rpx;
						font-family: Inter, Inter;
						font-weight: 550;
						font-size: 26rpx;
						color: #19e820;
						line-height: 36rpx;
						text-align: right;
					}
				}

				.item-box {
					margin-top: 300rpx;
				}

				.item {
					margin-top: 24rpx;
					width: 686rpx;
					height: 264rpx;
					background: #ffffff;
					border-radius: 24rpx 24rpx 24rpx 24rpx;

					.head {
						display: flex;
						height: 170rpx;

						.item-img {
							margin-top: 28rpx;
							width: 104rpx;
							height: 104rpx;
							border-radius: 50rpx;
							margin-left: 28rpx;
						}

						.item-info {
							width: 506rpx;
							margin-left: 24rpx;
							height: 170rpx;

							.item-title {
								display: flex;
								height: 44rpx;
								margin-top: 34rpx;
								width: 506rpx;

								.title-text {
									font-size: 32rpx;
									color: #333333;
									font-weight: bold;
									height: 48rpx;
									line-height: 48rpx;
								}

								.member-tag {
									font-size: 24rpx;
									color: red;
									margin-left: 14rpx;
									padding: 0 10rpx;
									border: 1rpx solid red;
									font-weight: 400;
									font-size: 20rpx;
									color: #ed6e3e;
									line-height: 28rpx;
									text-align: center;
									height: 32rpx;
									border-radius: 100rpx 100rpx 100rpx 100rpx;
									border: 1rpx solid #ed6e3e;
									margin-top: 8rpx;
								}
							}

							.item-details {
								font-size: 24rpx;
								color: #666;
								margin: 10rpx 0;
								width: 506rpx;
								height: 34rpx;
								line-height: 34rpx;
								display: flex;

								.item-meta {
									width: 300rpx;
									text-align: left;
								}

								.item-right {
									width: 206rpx;
									text-align: right;
								}
							}

							.abc {
								display: flex;
								font-weight: 400;
								font-size: 24rpx;
								color: #777777;
								height: 34rpx;
								width: 506rpx;

								.view_imag {
									width: 28rpx;
									height: 28rpx;
									margin-top: 3rpx;
								}

								.abc_o {
									height: 34rpx;
									line-height: 34rpx;
									width: 239rpx;
									height: 34rpx;
									text-align: left;
								}

								.abc_t {
									width: 239rpx;
									height: 34rpx;
									height: 34rpx;
									line-height: 34rpx;
									text-align: right;
								}
							}
						}
					}

					.footer {
						padding: 0 30rpx;
						height: 94rpx;
						display: flex;
						justify-content: space-between;

						.num-list {
							display: flex;
							justify-content: space-between;

							.text {
								height: 94rpx;
								line-height: 94rpx;
								font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
								font-weight: 500;
								font-size: 24rpx;
								color: #a3a3a3;
								text-align: left;
							}

							.show {
								margin-left: 10rpx;
								height: 94rpx;
								line-height: 94rpx;
							}
						}
					}
				}
			}
		}
	}
</style>